import { Injectable } from '@nestjs/common'
import { CrudRequest } from '@nestjsx/crud'
import { TypeOrmCrudService } from '@nestjsx/crud-typeorm'
import { Repository } from 'typeorm'

@Injectable()
export class BaseCrudService<T> extends TypeOrmCrudService<T> {
  constructor(protected repo: Repository<T>) {
    super(repo)
  }

  // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
  async deleteOne(req: CrudRequest): Promise<void | T> {
    req.options.query = req.options.query ?? {}
    req.options.query.softDelete = true
    return await super.deleteOne(req)
  }
}
